package com.schoolcloud.social.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.common.util.PageUtil;
import com.schoolcloud.common.util.UserContext;
import com.schoolcloud.social.entity.SocBard;
import com.schoolcloud.social.mapper.SocBardMapper;
import com.schoolcloud.social.query.BardQuery;
import com.schoolcloud.social.service.SocBardService;
import com.schoolcloud.social.vo.SocBardVO;
import com.schoolcolud.daomybatisplus.dto.MpPageUtil;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author hongmizfb
* @description 针对表【soc_bard(贴吧表)】的数据库操作Service实现
* @createDate 2025-02-11 12:18:36
*/
@Service
public class SocBardServiceImpl extends ServiceImpl<SocBardMapper, SocBard>
    implements SocBardService{

    @Override
    public void createBard(SocBard socBard) {
        socBard.setUserId(UserContext.getUser());
        socBard.setCreateTime(new Date());
        save(socBard);
    }

    @Override
    public PageDTO<SocBard> getBardPage(BardQuery query) {
        String keywords = query.getKeywords();
        int status = query.getStatus();
        Page<SocBard> page = lambdaQuery().like(StrUtil.isNotBlank(keywords), SocBard::getBardName, keywords)
                .eq(status != -1, SocBard::getStatus, status)
                .page(query.toMpPage());
        return MpPageUtil.of(page,SocBard.class);
    }

    @Override
    public SocBard getBardInfoById(String bardId) {
        return baseMapper.getBardInfoById(bardId);
    }

    @Override
    public SocBard getBardByPostId(String postId) {
        return baseMapper.getBardByPostId(postId);
    }


}




